//
//  StatusViewModel.m
//  weibo110
//
//  Created by 臧松 on 15/12/30.
//  Copyright © 2015年 臧松. All rights reserved.
//
#define StatusCellRetweetedId @"StatusCellRetweetedId"

#import "StatusViewModel.h"
#import "StatusCell.h"
#import "StatusRetweetedCell.h"
#import "StatusNormalCell.h"

@implementation StatusViewModel

-(CGFloat)rowHeight{
    
    StatusCell * cell;
    if (self.status.retweeted_status != nil) {
        cell = [[StatusRetweetedCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:StatusCellRetweetedId];
    }else{
        cell = [[StatusNormalCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:StatusCellNormalId];
    }
        return [cell rowHeightWithModel:self];
}

-(NSURL *)userProfileUrl{
    
    return [NSURL URLWithString:self.status.user.profile_image_url];
}

-(UIImage *)userDefaultIconView{
    
    return [UIImage imageNamed:@"avatar_default_big"];
}

-(UIImage *)userNumberImage{
    if (self.status.user.mbrank > 0 && self.status.user.mbrank < 7) {
        
        return [UIImage imageNamed:[NSString stringWithFormat:@"common_icon_membership_level%ld",(long)self.status.user.mbrank]];
    }
    return nil;
}

-(UIImage *)userVipImage{
    switch (self.status.user.verified_type) {
        
        case 0:
            return [UIImage imageNamed:@"avatar_vip"];
        case 2:
            return [UIImage imageNamed:@"avatar_enterprise_vip"];
        case 3:
            return [UIImage imageNamed:@"avatar_enterprise_vip"];
        case 5:
            return [UIImage imageNamed:@"avatar_enterprise_vip"];
        case 220:
            return [UIImage imageNamed:@"avatar_grassroot"];
        default:
            return nil;
    }
}
-(NSString *)retweetedText{
    Status * s = self.status.retweeted_status;
    if (s == nil) {
        return nil;
    }
    return [NSString stringWithFormat:@"@%@:%@",s.user.screen_name,s.text];
}
-(NSString *)cellId{
    if (self.status.retweeted_status != nil) {
        return StatusCellRetweetedId;
    }else{
        return StatusCellNormalId;
    }
}
-(instancetype)initWithStatus:(Status *)status{
    if (self = [super init]) {
        
        self.status = status;
        NSArray * urls = status.retweeted_status.pic_urls.count > 0 ? status.retweeted_status.pic_urls : status.pic_urls;
        
            NSMutableArray *arrayM = [NSMutableArray array];
            for (NSDictionary * dict in urls) {
                
                NSURL * url = [NSURL URLWithString:dict[@"thumbnail_pic"]];
                [arrayM addObject:url];
            }
            self.thumbnailUrls = arrayM;
        
    }
    return self;
}
-(NSString *)description{
    
    return self.thumbnailUrls.description;
}
@end
